/*
 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

function main(): int throws{
{%- filter indent(width=4) %}
let failCounter: int = 0;
let testResult: int = 0;

{%- if item.method_expected_data_nature == "structure" %}
{%- for key, value in item.result_type_signature.items() %}
let {{.key }} : {{.item.result_type_signature[key]}}
{%- endfor %}
{% endif %}
{%- for test_name, test_data in item.method_test_index_data.items() %}
{%- if item.method_expected_exception is defined %}
testResult = checkTestResult({{.item.method_name}}{{.test_name|capitalize}}())
{%- else %}
{%- if item.method_expected_data_nature == "structure" %}
{%- for key, value in item.method_expected_data[test_name].items() %}
{{.key }} = {{.value}}
{%- endfor %}
testResult = checkTestResult({{.item.method_name}}{{.test_name|capitalize}}(), {{.item.method_expected_data[test_name].keys() | join(", ")}});
{%- else %}
let expectedData{{.test_name|capitalize}} : {{.item.result_type}} = {{.item.method_expected_data[test_name]}}
testResult = checkTestResult({{.item.method_name}}{{.test_name|capitalize}}(), expectedData{{.test_name|capitalize}})
{%- endif %}
{%- endif %}
printTestVerdict(testResult, "{{.test_name}}")
failCounter += testResult
{% endfor %}
if (failCounter > 0) return 1
return 0;
{%- endfilter %}
}

function printTestVerdict(flag: int, testName: String) {
{%- filter indent(width=4) %}
if (flag == 0) {
{%- filter indent(width=4) %}
console.println(testName + " : PASSED")
{% endfilter %}
} else {
{%- filter indent(width=4) %}
console.println(testName + " : FAILED")
{%- endfilter %}
}
{%- endfilter %}
}
